package com.genius.smsdao.coursemanage.domain;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.genius.smsbase.Domain.BaseEntity;
import com.genius.smsdao.attendancemanage.domain.Attendance;
import com.genius.smsdao.attendancemanage.domain.Way;
import com.genius.smsdao.scoremanage.domain.Score;
import com.genius.smsdao.studentmanage.domain.Student;
import com.genius.smsdao.teachermanage.domain.Teacher;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;


/**
 * @Entity:Course 课程实体类
 * 对应数据库表名：course
 * @author：gpf
 */
@Entity
@Table(name = "course")
public class Course extends BaseEntity<Long> {

    @Column
    private String name;
    //学分
    @Column
    private Double credit;
    //课程人数
    @Column
    private Integer number;
    //剩余人数
    @Column
    private Integer remaining;
    //上课时间
    @Column
    private String time;

    //课程到教师多对一关系
    @JsonIgnoreProperties(value = "courseList")
    @ManyToOne(targetEntity = Teacher.class,fetch = FetchType.LAZY)
    @JoinColumn(name = "teacher_id",referencedColumnName = "id")
    private Teacher teacher;

    //课程到CourseKind多对一关系
    @JsonIgnoreProperties(value = "courseList")
    @ManyToOne(targetEntity = CourseKind.class,fetch = FetchType.LAZY)
    @JoinColumn(name = "course_kind_id",referencedColumnName = "id")
    private CourseKind courseKind;

    //课程到学生的多对多关系，课程被选
    @JsonIgnoreProperties(value = "courseList")
    @ManyToMany(mappedBy = "courseList")
    private List<Student> studentList;

    //课程到成绩的一对多关系
    @JsonIgnoreProperties(value = "course")
    @OneToMany(mappedBy = "course",cascade = {CascadeType.REMOVE,CascadeType.REFRESH},fetch = FetchType.LAZY)
    private List<Score> scoreList;

    //课程到考勤的多对一关系，考勤被打
    @JsonIgnoreProperties(value = "courseList")
    @ManyToOne(targetEntity = Attendance.class,fetch = FetchType.LAZY)
    @JoinColumn(name = "attendance_id",referencedColumnName = "id")
    private Attendance attendance;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Teacher getTeacher() {
        return teacher;
    }

    public void setTeacher(Teacher teacher) {
        this.teacher = teacher;
    }

    public CourseKind getCourseKind() {
        return courseKind;
    }

    public void setCourseKind(CourseKind courseKind) {
        this.courseKind = courseKind;
    }

    public List<Student> getStudentList() {
        return studentList;
    }

    public void setStudentList(List<Student> studentList) {
        this.studentList = studentList;
    }

    public List<Score> getScoreList() {
        return scoreList;
    }

    public void setScoreList(List<Score> scoreList) {
        this.scoreList = scoreList;
    }

    public Attendance getAttendance() {
        return attendance;
    }

    public void setAttendance(Attendance attendance) {
        this.attendance = attendance;
    }

    public Double getCredit() {
        return credit;
    }

    public void setCredit(Double credit) {
        this.credit = credit;
    }

    public Integer getNumber() {
        return number;
    }

    public void setNumber(Integer number) {
        this.number = number;
    }

    public Integer getRemaining() {
        return remaining;
    }

    public void setRemaining(Integer remaining) {
        this.remaining = remaining;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    @Override
    public String toString() {
        return "Course{" +
                "name='" + name + '\'' +
                ", credit=" + credit +
                ", number=" + number +
                ", remaining=" + remaining +
                ", time='" + time + '\'' +
                ", teacher=" + teacher +
                ", courseKind=" + courseKind +
                ", createTime=" + createTime +
                ", updateTime=" + updateTime +
                ", id=" + id +
                '}';
    }
}
